package easy;

import java.util.HashMap;
import java.util.Map;

public class Solution_496 {

    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        Map<Integer, Integer> indexMap = new HashMap<>(nums2.length);
        for (int i = 0; i < nums2.length; i++) {
            indexMap.put(nums2[i], i);
        }
        for (int i = 0; i < nums1.length; i++) {
            int num2Index = indexMap.get(nums1[i]);
            int val = -1;
            for (int j = num2Index + 1; j < nums2.length; j++) {
                if (nums2[j] > nums1[i]) {
                    val = nums2[j];
                    break;
                }
            }
            nums1[i] = val;
        }
        return nums1;
    }

    public static void main(String[] args) {
        Solution_496 model = new Solution_496();
//        int[] ints = model.nextGreaterElement(new int[]{4, 1, 2}, new int[]{1, 3, 4, 2});
//        Inte[] ints = model.nextGreaterElement(new int[]{2,4}, new int[]{1, 2, 3, 4});
//        PrintUtils.array(ints);
    }
}
